import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { FEE_BILL, INVOICE_LIST, PAY_LIST, WATER_USAGE } from 'src/app/api/fee-enquiry/fee-enquiry';

@Injectable({providedIn: 'root'})
export class FeeEnquiryService {
  constructor(
    private http: HttpClient
  ) { }
  
  /**
   * 查询水费账单 | 欠费列表
   * @param code 
   * @param pageNumber 
   * @param pageSize 
   * @param state 是否只查询欠费
   * @returns 
   */
  _getFeeBill(code: string, pageNumber: number = 1, pageSize: number = 10, state: string = ''): Observable<any>{
    let args;
    if(state){
      args = {
        code, pageNumber, pageSize, state
      }
    }else{
      args = {
        code, pageNumber, pageSize
      }
    }
    
    return this.http.get(FEE_BILL, {
      params: new HttpParams({
        fromObject: args
      })
    })
  }

  /**
   * 缴费列表
   * @param usageCode 
   */
  _getPayList(usageCode: string, pageNumber = 1, pageSize = 20): Observable<any>{
    return this.http.get(PAY_LIST, {
      params: new HttpParams({ fromObject: { userNo: usageCode, pageNumber, pageSize } })
    })
  }

  _getInvoiceList(usageCode: string, pageNumber = 1, pageSize = 10): Observable<any>{
    return this.http.get(INVOICE_LIST, {
      params: new HttpParams({
        fromObject: { pageNumber, pageSize, code: usageCode }
      })
    })
  }

  _getWaterUsage(usageCode: string): Observable<any>{
    return this.http.get(WATER_USAGE + usageCode)
  }

  // 取消订单
  cancelOrder(outTradeNo: string): Observable<any>{
    let url = `/api/gsxmcp/cs/qp/v1.0/userPay/cancelled/${outTradeNo}`;
    return this.http.post(url, null);
  }
}